function filter(item) {
  if (item.meta && item.meta.name) {
    if (item.meta.link !== false && !item.name) {
      return false;
    }
    return true;
  }
  return false;
}

function map(_item) {
  const item = {
    routeName: _item.name,
    name: _item.meta.name,
    isLink: _item.meta.link !== false,
  };
  return item;
}

function getBreadCrumb(matched) {
  const items = matched.filter((item) => filter(item))
    .map((item) => map(item));
  return items;
}

export default getBreadCrumb;
